﻿using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using BlueCrestStudio.DataVirtualization.Client.StockDataService;

namespace BlueCrestStudio.DataVirtualization.Client.Data
{
    /// <summary>
    /// Demo implementation of IItemsProvider returning dummy customer items after
    /// a pause to simulate network/disk latency.
    /// </summary>
    public class StockDataProvider : IItemsProvider<Stock>
    {
        private StockDataServiceClient _client;

        /// <summary>
        /// Initializes a new instance of the <see cref="StockDataProvider"/> class.
        /// </summary>
        public StockDataProvider()
        {
            _client = new StockDataServiceClient();
            
        }

        /// <summary>
        /// Fetches the total number of items available.
        /// </summary>
        /// <returns></returns>
        public int FetchCount()
        {
            Trace.WriteLine("FetchCount");
            //Thread.Sleep(_fetchDelay);
            return _client.FetchCount(); 
        }

        /// <summary>
        /// Fetches a range of items.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The number of items to fetch.</param>
        /// <returns></returns>
        public IList<Stock> FetchRange(int startIndex, int count)
        {
            Trace.WriteLine("FetchRange: "+startIndex+","+count);
            //Thread.Sleep(_fetchDelay);
            return _client.FetchRange(startIndex, count); 
        }
    }
}
